package cn.stylefeng.guns.sys.modular.system.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.log.LogObjectHolder;
import cn.stylefeng.guns.sys.modular.system.entity.Archives;
import cn.stylefeng.guns.sys.modular.system.entity.BtyArchives;
import cn.stylefeng.guns.sys.modular.system.model.params.ArchivesParam;
import cn.stylefeng.guns.sys.modular.system.service.ArchivesService;
import cn.stylefeng.roses.core.base.controller.BaseController;

import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 离职人员维护
 *
 * @author yxc
 * @Date 2021-05-13 13:05:08
 */
@Controller
@RequestMapping("/archives")
public class ArchivesController extends BaseController {

    private String PREFIX = "/modular/system/archives";

    @Autowired
    private ArchivesService archivesService;

    /**
     * 跳转到主页面
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/archives.html";
    }

    /**
     * 新增页面
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/archives_add.html";
    }

    /**
     * 编辑页面
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("/edit/{id}")
    public String edit(@PathVariable Long id, Model model) {
        Archives archives = this.archivesService.getById(id);
        model.addAllAttributes(BeanUtil.beanToMap(archives));
        LogObjectHolder.me().set(archives);
        return PREFIX + "/archives_edit.html";
    }

    /**
     * 新增接口
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ArchivesParam archivesParam) {
        this.archivesService.add(archivesParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ArchivesParam archivesParam) {
        this.archivesService.update(archivesParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ArchivesParam archivesParam) {
        this.archivesService.delete(archivesParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ArchivesParam archivesParam) {
        Archives detail = this.archivesService.getById(archivesParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author yxc
     * @Date 2021-05-13
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ArchivesParam archivesParam) {
        return this.archivesService.findPageBySpec(archivesParam);
    }

    /**
     * 导出excel列表
     */
    @RequestMapping(value = "/listExport")
    @ResponseBody
    public Object listExport() {
        return this.archivesService.listExport();
    }

    /**
     * 恢复档案
     *
     */
    @ResponseBody
    @RequestMapping("/recovery")
    public ResponseData recovery(ArchivesParam archivesParam) {
         this.archivesService.recovery(archivesParam);
        return ResponseData.success();
    }

}


